package com.group.controller;

import com.group.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.entity.Cart;
import utils.BaseController;
import javax.servlet.http.HttpServletResponse;


@Api(tags = "购物车信息")
@Controller
@RequestMapping(value = "/cart",produces = "application/json;charset=utf-8")
public class CartController extends BaseController {

    @Autowired
    private CartService cartService;

    //增加购物车功能
    @ApiOperation("增加购物车")
    @RequestMapping(value = "addCart.do",method = RequestMethod.POST)
    @ResponseBody
    public String addCart(@RequestBody Cart cart, HttpServletResponse resp){
        System.out.println("增加购物车:"+cart);
        return writerSuccessResult(cartService.addCart(cart),resp);
    }

    //修改购物车功能
    @ApiOperation("修改购物车")
    @RequestMapping(value = "updateCart.do",method = RequestMethod.POST)
    @ResponseBody
    public String updateCart(@RequestBody Cart cart, HttpServletResponse resp){
        System.out.println("修改购物车:"+cart);
        return writerSuccessResult(cartService.updateCart(cart),resp);
    }

    //删除购物车功能
    @ApiOperation("删除购物车")
    @RequestMapping(value = "deleteCart.do",method = RequestMethod.POST)
    @ResponseBody
    public  String deleteCart(@RequestBody Cart cart, HttpServletResponse resp){
        System.out.println("删除购物车:"+cart);
       return writerSuccessResult(cartService.deleteCart(cart),resp);
    }

    //展示购物车功能
    @ApiOperation("展示购物车")
    @RequestMapping(value = "showCart.do",method = RequestMethod.POST)
    @ResponseBody
    public String showCartByUserID(@RequestBody Long userID, HttpServletResponse resp){
        System.out.println("展示购物车用户id:"+userID);
        return writerSuccessResult(cartService.showCart(userID),resp);
    }


}
